# coding: utf8
# datetime: 2021-04-08
# 题目地址: https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array


from typing import List


# class Solution:
#     def findMin(self, nums: List[int]) -> int:
#         len_nums = len(nums)
#         if len_nums ==0 :
#             return 0
#         low, high = 0, len_nums-1
#         while low < high :
#             point = (low+high)//2
#             if nums[point] < nums[high]:
#                 high = point
#             else:
#                 low = point+1
#         return nums[low]


# a = Solution()
# print(a.findMin([4,5,6,7,0,1,2]))

def binarySearch(nums, key):
    len_num = len(nums)
    low, high = 0, len_num-1
    while True:
        point = (low+high)//2
        if key == nums[point]:
            return point
        if nums[point] < nums[high]:
            high = point-1
        else:
            low = point+1

print(binarySearch([4,5,6,7,0,1,2], 0))